import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import BIll.BLLRoom;
import BIll.BLLRoom_user;
import BIll.BLLUser;
import tool.BllFactory;

public class CheckOutServlet extends HttpServlet{
	private BllFactory bllFactory = BllFactory.getBllFactory();

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset = utf-8");
		
		int roomid = Integer.parseInt(req.getParameter("roomid"));
		String name = new String(req.getParameter("name").getBytes("ISO-8859-1"),"utf-8");
		String idcard = new String(req.getParameter("idcard").getBytes("ISO-8859-1"),"utf-8");
		
		BLLUser bllUser = bllFactory.getInstance(BLLUser.class);
		BLLRoom bllRoom = bllFactory.getInstance(BLLRoom.class);
		BLLRoom_user bllRoomUser = bllFactory.getInstance(BLLRoom_user.class);
		boolean b = bllUser.CheckOut(idcard);
		int roomprice = bllRoom.checkOut(roomid);
		int day = bllRoomUser.checkOut(roomid);
		
		int check=-1;
		if(b == true && roomprice !=-1 && day !=-1){
			check=roomprice*day;
		}
		PrintWriter pw = resp.getWriter();
		pw.print(check);
		pw.close();
	}
	
	
}